package com.dzsw.netty.basic.nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

public class MappedByteBufferMain {

    public static void main(String[] args) throws Exception {
        String filePath = "d:\\test.txt";
        try (RandomAccessFile raf = new RandomAccessFile(filePath, "rw");
             FileChannel fileChannel = raf.getChannel()) {
            MappedByteBuffer mBuff = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, raf.length());
            byte[] bs = "我的".getBytes(StandardCharsets.US_ASCII);
            mBuff.put(bs, 0, bs.length);
//            mBuff.put(2, (byte) 'M');
//            mBuff.put(3, (byte) 'W');
        }
    }
}
